Skip to content

fix: prevent image decode future from completing twice - #520

Merged
rickdijk merged 2 commits into
Baseflow:mainfrom
dao-wkm:fix/decode-image-completer
Sep 19, 2026
Merged

rickdijk merged 2 commits into
Baseflow:mainfrom
dao-wkm:fix/decode-image-completer

Conversation

@dao-wkm

@dao-wkm dao-wkm commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Bug fix.

⤵️ What is the current behavior?

When ImageCacheManager resizes a multi-frame image, such as an animated PNG,
_decodeImage keeps its ImageStreamListener registered after receiving the
first frame.

Subsequent frames call Completer.complete(...) again, causing:

StateError: Bad state: Future already completed

🆕 What is the new behavior (if this is a feature change)?

_decodeImage now removes its listener after the first frame and guards
success/error completion with Completer.isCompleted.
Animated PNGs can be resized without throwing Future already completed.

💥 Does this PR introduce a breaking change?

No.

🐛 Recommendations for testing

  1. Use a CacheManager with ImageCacheManager.
  2. Request a resized animated PNG by passing maxWidth and/or maxHeight.
  3. Confirm that subsequent animation frames do not throw an exception.
    Example APNG:
    https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png
    A local APNG fixture is recommended for an automated regression test.
CachedNetworkImage(
      imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png',
      width: 100,
      height: 100,
      maxWidthDiskCache: 256,
      maxHeightDiskCache: 256,
)

📝 Links to relevant issues/docs

Fixes #400

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

@rickdijk
rickdijk force-pushed the fix/decode-image-completer branch from 62ae6ac to b36fc8d Compare September 15, 2026 23:55
@rickdijk
rickdijk changed the base branch from develop to main September 16, 2026 00:17

@rickdijk rickdijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, and for the reproduction steps.

Please make sure CHANGELOG.md is updated with a version bump and description. Bump the version in pubspec.yaml too. Make sure the formatter and analyzer have been applied and fixed if applicable.

@rickdijk
rickdijk force-pushed the fix/decode-image-completer branch from b36fc8d to 2c51cbf Compare September 17, 2026 21:54
@dao-wkm

dao-wkm commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

@rickdijk Thanks! I’ve rebased the branch onto main, bumped the package version to 3.4.5, updated the changelog, and verified formatting, analysis, and tests.

@rickdijk
rickdijk merged commit 313bfa1 into Baseflow:main Sep 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad state: Future already completed

2 participants